package me.zk.practice1.s;

/**
 * @author zhangkai
 * @date 2023/7/14 11:44
 */
public class LS_Offer_53_2 {
    public int missingNumber(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
            if (i!=nums[i]) {
                return i;
            }
        }
        return nums.length;
    }

    public static int missingNumber2(int[] nums) {
        int l=0,r = nums.length-1;
        while (l <= r) {
            int mid = (r+l)/2;
            if (mid == nums[mid]) {
                l = mid+1;
            } else {
                r = mid-1;
            }
        }
        return l;
    }

    public static void main(String[] args) {
        System.out.println(missingNumber2(new int[]{0,1,2,3,5,6,7,8,9}));
    }
}
